import React, {useState, useEffect} from 'react';
import {Button, Divider, message, Table, Modal} from 'antd';
import {ColumnsType} from "antd/lib/table";
import styles from './index.module.scss';
import {IPageResponse, IParam} from "@/common/common";
import {apiGetSystemLogList} from "@/apis/log";

const {confirm} = Modal;

const TableList: React.FC<any> = () => {

  const [loading, setLoading] = useState<boolean>(false);
  const [params, setParams] = useState<IParam>({page: 1, size: 10});
  const [pageResponse, setPageResponse] = useState<IPageResponse<any>>({pageInfo: {page: 1, size: 10, total: 0}})

  useEffect(() => {
    apiGetSystemLogList({}, true).then(res => {
      setPageResponse(res);
    }).finally(() => setLoading(false));
  }, [params]);

  const columns: ColumnsType<any> = [
    {
      title: '用户名',
      key: 'name',
      dataIndex: 'name',
      align: "center",
    },
    {
      title: '昵称',
      key: 'nickName',
      dataIndex: 'nickName',
      align: "center",
    },
    {
      title: '手机号',
      key: 'mobile',
      dataIndex: 'mobile',
      align: "center",
    },
    {
      title: '邮箱',
      key: 'email',
      dataIndex: 'email',
      align: "center",
    },
    {
      title: '部门',
      key: 'deptName',
      dataIndex: 'deptName',
      align: "center",
    },
    {
      title: '职位',
      key: 'jobName',
      dataIndex: 'jobName',
      align: "center",
    },
    {
      title: '角色',
      key: 'roleName',
      dataIndex: 'roleName',
      align: "center",
    },
    {
      title: '状态',
      key: 'status',
      dataIndex: 'status',
      align: "center",
      render: (text: any, record: any) => {
        return text;
      },
    },
    {
      title: '操作',
      key: 'option',
      dataIndex: 'option',
      align: "center",
      render: (text: any, record: any) => {
        return text;
      },
    },
  ]

  return (
    <Table
      rowKey={"id"}
      columns={columns}
      className={styles.container}
      dataSource={pageResponse.data || []}
      pagination={{
        current: pageResponse.pageInfo.page || 0,
        pageSize: pageResponse.pageInfo.size || 10,
        showQuickJumper: true,
        showSizeChanger: true,
        pageSizeOptions: ["10", "20", "30"],
        total: pageResponse.pageInfo.total || 0,
        showTotal: (total) => `共 ${total} 条`,
        onChange: (pageNo, pageSize) => {
          setParams({...params, ...{page: pageNo, size: pageSize}})
        }
      }}
    />
  )
}

export default TableList
